﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Meraz.Core.Model;
using Meraz.Core.Repositories;
namespace Meraz.Core.Commands
{
    public interface IRemoveTwitterStudyCommand : ICommand<bool> {
        int StudyID { get; set; }
    }
    public class RemoveTwitterStudyCommand : BaseCommand, IRemoveTwitterStudyCommand
    {
        public RemoveTwitterStudyCommand(ITwitterStudyRepository repository) { Repository = repository ?? new TwitterStudyRepository(); } 
        public ITwitterStudyRepository Repository { get; set; }
        public bool Result { get; set; }
        public int StudyID { get; set; }
        public void Execute()
        {
            if (StudyID == 0)
                throw new ApplicationException("Invalid study ID");

            TwitterStudy study = Repository.GetById(StudyID);
            if (study == null)
                return;

            Repository.Delete(study);
            Result = true;
        }
    }
}
